home *** CD-ROM | disk | FTP | other *** search
- class Missile extends MovieClipHolder implements Steppable
- {
- var mc;
- var newAngle;
- var tm;
- var dm;
- static var MAX_SPEED = 6;
- static var ACCEL = 2;
- static var DAMAGE = 1;
- static var GRACE_TIMER = 12;
- static var MISSILE_TIMER = 150;
- static var missiles = new ObjectList();
- var xspeed = 0;
- var yspeed = 0;
- var graceTimer = 0;
- var skipSwitch = true;
- function Missile(x, y, newAngle)
- {
- super(_root.attachMovie("missile1","missile1" + _root.getNextHighestDepth(),_root.getNextHighestDepth()));
- this.mc._x = x;
- this.mc._y = y;
- this.newAngle = newAngle;
- this.createTrailManager();
- this.createDebrisManager();
- this.createSound();
- Missile.add(this);
- Stepper.add(this);
- }
- function getMaxSpeed()
- {
- return Missile.MAX_SPEED;
- }
- function getAccel()
- {
- return Missile.ACCEL;
- }
- function getMissileTimer()
- {
- return Missile.MISSILE_TIMER;
- }
- function getGraceTimer()
- {
- return Missile.GRACE_TIMER;
- }
- static function add(m)
- {
- Missile.missiles.add(m);
- }
- static function remove(m)
- {
- Missile.missiles.remove(m);
- }
- function step()
- {
- this.followPlayer();
- if(this.graceTimer > this.getMissileTimer())
- {
- this.die();
- }
- this.graceTimer = this.graceTimer + 1;
- if(this.mc._x < 0 || this.mc._x > Stage.width || this.mc._y < 0 || this.mc._y > Stage.height)
- {
- this.outOfBounds();
- }
- }
- function createSound()
- {
- SoundManager.fireRedMissile();
- }
- function outOfBounds()
- {
- this.die();
- }
- function createTrailManager()
- {
- this.tm = new EfficientTrailManager(this.mc,this.mc.exhaust1,2,_root.effects < 3 ? null : 16711680,this.getTrailLength(),true,50);
- }
- function getTrailLength()
- {
- if(_root.effects <= 1)
- {
- return 6;
- }
- return 9;
- }
- function createDebrisManager()
- {
- if(_root.effects >= 2)
- {
- this.dm = new DebrisManager(16711680,1);
- }
- }
- function followPlayer()
- {
- if(this.skipSwitch)
- {
- var _loc3_ = undefined;
- if(this.isGrace() && this.newAngle)
- {
- _loc3_ = CustomMath.degToRad(this.newAngle);
- }
- else
- {
- _loc3_ = Math.atan2(_root.player.getMovie()._y - this.mc._y,_root.player.getMovie()._x - this.mc._x);
- }
- var _loc4_ = this.xspeed * this.xspeed + this.yspeed * this.yspeed;
- var _loc5_ = this.getMaxSpeed() * this.getMaxSpeed();
- this.xspeed += this.getAccel() * Math.cos(_loc3_);
- this.yspeed += this.getAccel() * Math.sin(_loc3_);
- if(_loc4_ > _loc5_)
- {
- this.xspeed *= _loc5_ / _loc4_;
- this.yspeed *= _loc5_ / _loc4_;
- }
- }
- this.mc._x += this.xspeed;
- this.mc._y += this.yspeed;
- this.tm.makeTrail();
- this.skipSwitch = !this.skipSwitch;
- }
- function isGrace()
- {
- return this.graceTimer < this.getGraceTimer();
- }
- function getX()
- {
- return this.mc._x;
- }
- function getY()
- {
- return this.mc._y;
- }
- function getDamage()
- {
- return Missile.DAMAGE;
- }
- function hit(m, shapeFlag, isPlayer)
- {
- if(isPlayer || !this.isGrace())
- {
- return m.hitTest(this.mc._x,this.mc._y,shapeFlag);
- }
- return false;
- }
- function die()
- {
- this.dm.createDebrisField(this.mc._x,this.mc._y);
- Stepper.remove(this);
- Missile.remove(this);
- this.tm.die();
- new Explosion(this.mc._x,this.mc._y,1,0);
- this.mc.removeMovieClip();
- }
- }
-